"""
@Author    : ghenyar
@Time      : 2025/9/5 13:10
@File      : settings
@Desc      : 
"""
from typing import Optional, Union

from pydantic import BaseModel, field_validator
from pydantic_core.core_schema import ValidationInfo

from app.common.exception.exceptions import ValidationException


class ChangePassword(BaseModel):
    """修改当前登录账号密码"""
    old_password: str
    password: str
    conf_password: str

    @field_validator('old_password')
    def validate_old_password (cls, v):
        if not v:
            raise ValidationException('旧密码不能为空')
        return v

    @field_validator('password')
    def validate_password (cls, v):
        if not v:
            raise ValidationException('新密码不能为空')
        return v

    @field_validator('conf_password')
    def validate_conf_password (cls, v, info: ValidationInfo):
        if not v:
            raise ValidationException('确认密码不能为空')
        if v != info.data.get('password'):
            raise ValidationException('新密码和确认密码不一致')
        return v


class FileGroupSchemas(BaseModel):
    """
    文件分组请求体
    """
    id: int
    name: str

    @field_validator("name")
    def validate_old_password (cls, v):
        if not v:
            raise ValidationException("分组名称不能为空")
        return v


class UpSort(BaseModel):
    """更新排序"""
    id: int
    sort: Optional[Union[int, str]] = None


class UpStatus(BaseModel):
    """
    更新状态
    """
    id:int
    status: int


class Agreement(BaseModel):
    title: str
    types:str
    content: str
    status: Optional[int]=0

    @field_validator("title")
    def validate_title(cls, v):
        if not v:
            raise ValidationException("协议标题不能为空")
        return v

    @field_validator("types")
    def validate_types(cls, v):
        if not v:
            raise ValidationException("请选择类别")
        return v



